import type R from '@/types/conduit/R'
import type { PageResponse } from '@/types/generic/PageResponse'
import type OrderEvaluateSubmitDTO from '@/types/param/order'
import type { OrderListForUserPage, RequestPayDTO, SubmitOrder } from '@/types/param/order'
import type {
  CreateOrderComplete,
  OrderDetailForEvaluate,
  OrderForUser,
  OrderInfo,
  OrderForMapShow,
  UserMapOrder,
  OrderForUserEvaluateVO
} from '@/types/response/order'
import request from '@/utils/request'

export const create = (submitOrder: SubmitOrder): Promise<R<CreateOrderComplete>> =>
  request({
    url: `/order/order/create`,
    method: 'POST',
    data: { ...submitOrder, ...{ isImmediate: submitOrder.isImmediate == null || submitOrder.isImmediate ? 1 : 0 } }
  })

export const cancel = (orderId: number): Promise<R<null>> =>
  request({
    url: `/order/order/cancel/${orderId}`,
    method: 'POST'
  })
// 模拟支付接口
export const requestPay = (requestPayDTO: RequestPayDTO): Promise<R<{ [key: string]: String }>> =>
  request({
    url: `/order/order/request-pay`,
    method: 'POST',
    data: requestPayDTO
  })

export const info = (orderId: string): Promise<R<OrderInfo>> =>
  request({
    url: `/order/order/info/${orderId}`,
    method: 'GET'
  })
export const list = (orderListForUserPage: OrderListForUserPage): Promise<R<PageResponse<OrderForUser>>> =>
  request({
    url: `/order/order/list-for-user`,
    method: 'GET',
    params: orderListForUserPage
  })

export const dishes = (orderId: number): Promise<R<OrderDetailForEvaluate[]>> =>
  request({
    url: `/order/order/dishes`,
    method: 'GET',
    params: { orderId }
  })

/**
 * 获取用户的订单信息-进行地图展示
 */
export const getOrderForMapShow = (orderId?: number): Promise<R<OrderForMapShow>> =>
  request({
    url: `/order/order/order-for-map-show`,
    method: 'GET',
    params: { orderId }
  })
/**
 * 获取用户MapForOrder的订单列表
 */
export const listForMapShow = (): Promise<R<UserMapOrder[]>> =>
  request({
    url: `/order/order/list-for-map-show`,
    method: 'GET'
  })

/**
 * 获取订单评价需要的VO
 */
export const getOrderForUserEvaluate = (orderId: number | string): Promise<R<OrderForUserEvaluateVO>> =>
  request({
    url: `/order/order-evaluate/for-user-evaluate`,
    method: 'GET',
    params: { orderId }
  })

/**
 * 提交订单评价
 */
export const submitOrderEvaluation = (orderEvaluateSubmitDTO: OrderEvaluateSubmitDTO): Promise<R<null>> =>
  request({
    url: `/order/order-evaluate/submit`,
    method: 'POST',
    data: orderEvaluateSubmitDTO
  })
